﻿<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns="http://www.w3.org/1999/xhtml">


	<xsl:output method="html"
		encoding="utf-8"
		indent="yes"
		doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

	<xsl:param name="pClientProcessingDurationms" select="0"/>
	<xsl:param name="pPageIndex" select="0"/>
	<xsl:param name="pPageSize" select="10"/>
	<xsl:param name="pPageCount" select="ceiling (/PFRs/PFR[1]/P/@RCount div $pPageSize)"/>
	<xsl:param name="pRowCount" select="/PFRs/PFR[1]/P/@RCount"/>
	<xsl:param name="pPageRowCount" select="count (/PFRs/PFR)"/>

	<xsl:template match="/">
		<div class="filRefSet">

			<link href="xslt/searchResultsGrid.css" type="text/css" rel="stylesheet" />

			<xsl:call-template name="PaggingInfo"/>
			
			<div class="items">
				<xsl:for-each select="//PFR">
					<xsl:apply-templates select="."/>
				</xsl:for-each>
			</div>

		</div>
	</xsl:template>

	<xsl:template name="PaggingInfo">		
		<div class="paggingInfo">
			<xsl:choose>
				<xsl:when test="$pPageRowCount = 0">
					<div class="empty">
						No fueron encontrados registros para su consulta
					</div>
				</xsl:when>
				<xsl:otherwise>
					<input type="button" class="first" value="Primero">
						<xsl:if test="$pPageIndex = 0">
							<xsl:attribute name="disabled">
							</xsl:attribute>
						</xsl:if>
						<xsl:attribute name="onclick">
							frmSearch.OnPageFirst ();
						</xsl:attribute>
					</input>
					<input type="button" class="previous" value="Anterior">
						<xsl:if test="$pPageIndex = 0">
							<xsl:attribute name="disabled">
							</xsl:attribute>
						</xsl:if>
						<xsl:attribute name="onclick">
							frmSearch.OnPagePrevious ();
						</xsl:attribute>
					</input>
					<div class="description">
						<xsl:attribute name="title">
							<xsl:value-of select="concat ('Procesamiento, Servidor: ', //@ProcessingDurationms, 'ms - Cliente: ', $pClientProcessingDurationms, 'ms')"/>
						</xsl:attribute>
						<xsl:value-of select="concat ('Página ', $pPageIndex + 1, ' de ', $pPageCount)"/>
					</div>
					<div class="total">
						<span class="lblTitleTotal">Total</span>
						<span class="lblValueTotal"><xsl:value-of select="$pRowCount" /></span>
					</div>
					<input type="button" class="last" value="Último">
						<xsl:if test="$pPageIndex = $pPageCount - 1">
							<xsl:attribute name="disabled">
							</xsl:attribute>
						</xsl:if>
						<xsl:attribute name="onclick">
							frmSearch.OnPageLast ();
						</xsl:attribute>
					</input>
					<input type="button" class="next" value="Siguiente">
						<xsl:if test="$pPageIndex >= $pPageCount - 1">
							<xsl:attribute name="disabled">
							</xsl:attribute>
						</xsl:if>
						<xsl:attribute name="onclick">
							frmSearch.OnPageNext ();
						</xsl:attribute>
					</input>
				</xsl:otherwise>
			</xsl:choose>
		</div>
	</xsl:template>

	<xsl:template name="Hs_JSON">
		<xsl:param name="Hs"></xsl:param>
		<xsl:text>[</xsl:text>
		<xsl:for-each select="$Hs/H">
			<xsl:if test="position() > 1">,</xsl:if>
			<xsl:value-of select="concat ('{ PageIndex: ', @PageIndex, ', WordSearchName: &#34;', @WordSearchName, '&#34;, X0:', @X0, ', Y0: ', @Y0, ', X1: ', @X1, ', Y1: ', @Y1, '}')"/>
		</xsl:for-each>
		<xsl:text>]</xsl:text>
	</xsl:template>

	
	<xsl:template name="XFR_JSON">
		<xsl:param name="XFR"></xsl:param>
		<xsl:param name="pIncludeChildren" select="0"></xsl:param>
		<xsl:text>{</xsl:text>
		<xsl:value-of select="concat ('OnlyName: &#34;', $XFR/@OnlyName, '&#34;, URLMD5: &#34;', $XFR/@URLMD5, '&#34;, ItemsCount: ', $XFR/@ItemsCount)"/>
		<xsl:if test="count($XFR/CFRs/FR) > 0 and $pIncludeChildren = 1">
			<xsl:text>, Children: [</xsl:text>
			<xsl:for-each select="$XFR/CFRs/FR">
				<xsl:if test="position() > 1">,</xsl:if>
				<xsl:call-template name="XFR_JSON">
					<xsl:with-param name="XFR" select="."></xsl:with-param>
				</xsl:call-template>
			</xsl:for-each>
			<xsl:text>]</xsl:text>
		</xsl:if>
		<xsl:if test="count($XFR/Hs/H) > 0">
			<xsl:text>, Hits: </xsl:text>
			<xsl:call-template name="Hs_JSON">
				<xsl:with-param name="Hs" select="$XFR/Hs"></xsl:with-param>
			</xsl:call-template>
		</xsl:if>
		<xsl:text>}</xsl:text>
	</xsl:template>
	

	<xsl:template match="PFR">
		<div class="item">
			<div class="itemRef">
				<div class="icon"></div>
				<div class="divItemCount" title="Total de paginas del documento y sus archivos">
					Pags. <xsl:value-of select="@ItemsCount + sum(CFRs/FR/@ItemsCount)"/>
				</div>
				<xsl:if test="count(Hs/H) &gt; 0 or count(CFRs/FR/Hs/H) &gt; 0">
					<div class="divHasHits" title="Tiene resultados dentro del contenido de al menos uno de los archivos del documento"></div>
				</xsl:if>
			</div>
			<div class="contents">
				<div class="tdLabel">Archivo(s)</div>
				<div class="tdField">
					<select class="ddlCFRs">
						<xsl:attribute name="id">
							<xsl:value-of select="concat('frmSearch_ddlItemPage_', P/@Ri)"/>
						</xsl:attribute>
						<option>
							<xsl:attribute name="value">
								<xsl:call-template name="XFR_JSON">
									<xsl:with-param name="XFR" select="."></xsl:with-param>
									<xsl:with-param name="pIncludeChildren" select="1"></xsl:with-param>
								</xsl:call-template>
							</xsl:attribute>
							<xsl:value-of select="@OnlyName"/>
							<xsl:if test="count(CFRs/FR) > 0">, Completo</xsl:if>
							<xsl:if test="count(Hs/H) > 0"> *</xsl:if>
						</option>
						<xsl:if test="count(CFRs/FR) > 0">
							<option>
								<xsl:attribute name="value">
									<xsl:call-template name="XFR_JSON">
										<xsl:with-param name="XFR" select="."></xsl:with-param>										
									</xsl:call-template>
								</xsl:attribute>
								<xsl:value-of select="@OnlyName"/>
								<xsl:if test="count(Hs/H) > 0"> * </xsl:if>
							</option>
						</xsl:if>
						<xsl:for-each select="CFRs/FR">
							<option>
								<xsl:attribute name="value">
									<xsl:call-template name="XFR_JSON">
										<xsl:with-param name="XFR" select="."></xsl:with-param>
									</xsl:call-template>
								</xsl:attribute>
								<xsl:value-of select="@OnlyName"/>
								<xsl:if test="count(Hs/H) > 0"> *</xsl:if>
							</option>
						</xsl:for-each>
					</select>
					<input type="button" value="Ver" title="Seleccione un archivo de la lista y de click para visualizar su contenido">
						<xsl:attribute name="onclick">
							var d = document.getElementById ('frmSearch_ddlItemPage_<xsl:value-of select="P/@Ri"/>'); frmSearch.ShowResultsPageIndex (d.value);
						</xsl:attribute>
					</input>
				</div>
				<div class="tdLabel">Ciudad</div>
				<div class="tdField">
					<xsl:value-of select="PFRLs/FRL[@Level='1']/@Name"/>
				</div>
				<div class="tdLabel">Clase</div>
				<div class="tdField">
					<xsl:value-of select="PFRLs/FRL[@Level='5']/@Name"/>
				</div>
				<div class="tdLabel">Carpeta</div>
				<div class="tdField">
					<xsl:value-of select="PFRLs/FRL[@Level='2']/@Name"/> -
					<xsl:value-of select="PFRLs/FRL[@Level='3']/@Name"/>
				</div>
				<div class="tdLabel">IPS</div>
				<div class="tdFieldIPS">
					<xsl:attribute name="title">
						<xsl:value-of select="concat (PEs/E[1]/@IdentificationTypeCode, ' - ', PEs/E[1]/@IdentificationNumber)"/>
					</xsl:attribute>
					<xsl:value-of select="PEs/E[1]/@Name"/>
				</div>
				<div class="tdLabel">Vigencia</div>
				<div class="tdField">
					<xsl:value-of select="concat ( substring (@VersionDateTime, 1, 4), '-', substring (@VersionDateTime, 6, 2), '-', substring (@VersionDateTime, 9, 2))"/>
				</div>
				<div class="tdLabel">Tipo</div>
				<div class="tdField">
					<xsl:value-of select="PFRLs/FRL[@Level='4']/@Name"/>
				</div>
				<div class="tdLabel">Modificado</div>
				<div class="tdField">
					<xsl:value-of select="@LastWriteDateTime"/>
				</div>
				<div class="tdLabel">Estado</div>
				<div class="tdField">
					<xsl:value-of select="@LastUpdateAction"/>
				</div>
			</div>
		</div>
	</xsl:template>

</xsl:stylesheet>